package com.macrounion.atv.service.service.impl;

import java.util.List;

import com.macrounion.atv.service.dto.req.DeviceReqDto;
import com.macrounion.atv.service.dto.req.DeviceStatusReqDto;
import com.macrounion.atv.service.dto.resp.DeviceListRespDto;
import com.macrounion.atv.service.entity.ext.DeviceStatusExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.macrounion.atv.service.entity.Device;
import com.macrounion.atv.service.entity.ext.DeviceExt;
import com.macrounion.atv.service.mapper.DeviceMapper;
import com.macrounion.atv.service.mapper.DeviceMapperExt;
import com.macrounion.atv.service.service.DeviceService;
import com.macrounion.base.service.service.impl.BaseServiceImpl;

@Service
public class DeviceServiceImpl extends BaseServiceImpl<DeviceMapper, Device> implements DeviceService {

	@Autowired
	private DeviceMapperExt deviceMapperExt;
	
	@Override
	public List<DeviceExt> getByProtocol(String protocol) {
		return deviceMapperExt.getByProtocol(protocol);
	}

    @Override
    public List<Device> getDeviceBySpotId(String spotId) {
        return deviceMapperExt.getDeviceBySpotId(spotId);
    }

	@Override
	public List<DeviceListRespDto> getDeviceList(DeviceReqDto deviceReqDto) {
		return deviceMapperExt.getDeviceList(deviceReqDto);
	}

	@Override
	public int findCount(Device device) {
		return deviceMapperExt.findCount(device);
	}

	@Override
	public List<DeviceStatusExt> getDeviceStatus(DeviceStatusReqDto deviceStatusReqDto) {
		return deviceMapperExt.getStatusList(deviceStatusReqDto);
	}

	@Override
	public List<Device> getAllDevice(Device device) {
		return deviceMapperExt.getAllDevice(device);
	}

	@Override
	public DeviceExt getDevice(String deviceCode) {
		return deviceMapperExt.getByDeviceCode(deviceCode);
	}

	@Override
	public String getDeviceIp(Device device) {
		if(device == null|| StringUtils.isEmpty(device.getDeviceCode()))
			return "";
//		return deviceCode.indexOf("_")<0?deviceCode:deviceCode.split("_")[1];
		if( StringUtils.isEmpty(device.getFlag()))
			return device.getDeviceCode();
		return device.getDeviceCode()+device.getFlag();
	}

	@Override
	public List<Device> getDevicesToVisual(Device device) {

		return deviceMapperExt.getDevicesToVisual(device);
	}

	@Override
	public DeviceExt getDeviceById(String deviceId) {
		return deviceMapperExt.getDeviceById(deviceId);
	}
}